<template>
 <div>
<h1>添加商品</h1>
     <p>商品: <input type="text" v-model="name"></p>
     <p>价格: <input type="text" v-model="price"></p>
     <p>图片: <input type='file' id='img'></p>
     <p>分类: 
         <select v-model="cate" >
             <option  :value="i.id" v-for="i in cate_list" :key="i.id">{{i.name}}</option>
         </select></p>
     <p><input type="button" value="添加" @click="add_goods"></p>
 </div>
</template>

<script>
 export default {
   data () {
     return {
         name:'',
         price:'',
         cate_list:[],
         cate:'1',
     }
   },
  methods: {
      add_goods() {
          var file = document.getElementById("img").files[0]
          let fdata = new FormData()
          fdata.append("name",this.name)
          fdata.append("price",this.price)
          fdata.append("cate",this.cate)
          fdata.append("img",file)
          this.axios({
              url:"/app01/goods/",
              method:"post",
              data:fdata
          }).then(resp=>{
              console.log(resp.data)
          })
      }
   },
   created() {
       this.axios({
          url:"/app01/cate/", 
       }).then(resp=>{
           console.log(resp.data)
           this.cate_list = resp.data
       })
   }
 }
</script>

<style>

 
</style>